{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8598ffbb",
   "metadata": {},
   "source": [
    "## *2023-10-18\n",
    "## *课程：python语言\n",
    "## *week05\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "321a1db7",
   "metadata": {},
   "source": [
    "# 1.用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "262c7266",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：Erdaty\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Erdaty'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input(\"请输入你的账号：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8b9addd4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号Erdaty\n",
      "请输入你的密码123456\n"
     ]
    }
   ],
   "source": [
    "username = input(\"请输入你的账号\")\n",
    "password = input(\"请输入你的密码\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "54ad70d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Erdaty\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "361156d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：Erdaty\n",
      "请输入你的密码：11111\n",
      "你输入的账号或密码错误\n"
     ]
    }
   ],
   "source": [
    "# 假设 正确的账号：Erdaty\n",
    "# 假设 正确的密码：123456\n",
    " \n",
    "# 登陆系统\n",
    "username = input(\"请输入你的账号：\")\n",
    "password = input(\"请输入你的密码：\")\n",
    "# 两种登陆可能，1：登陆成功，2：登陆失败\n",
    "if username == \"Erdaty\" and  password == \"123456\": \n",
    "        #注意：两个等号表示等于的意思，上一次冒号写成中文的，下次要注意。\n",
    "        # 情景1：账户和密码都正确，则登陆成功\n",
    "        print(\"欢迎vvVIP账户回来~~\")\n",
    "else:\n",
    "       #账号或密码存在不正确的数据\n",
    "        print(\"你输入的账号或密码错误\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04365716",
   "metadata": {},
   "source": [
    "##### *笔记\n",
    "     1.==代表判断左右两边是否相等，即\"等于\"\n",
    "     2.所有的符号要用英文的符号，例如冒号:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9d13d4c",
   "metadata": {},
   "source": [
    "# 2.用户输出（格式化）\n",
    "  ## 2.1注释\n",
    "  \n",
    "   >1.注释的内容（code）是不会被执行\n",
    "  \n",
    "   >2.\\#注释内容\n",
    "  \n",
    "   >3.\"\"\"注释内容\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b906f994",
   "metadata": {},
   "outputs": [],
   "source": [
    "#第一种：#表示单行注释，如下上述用户输入的学习中，每一行进行文字描述的注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "adb97a4b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "111\n"
     ]
    }
   ],
   "source": [
    "#第二种：\"\"\" 注释内容 \"\"\"  多行注释，用于记录之前写过的程序，不会被执行。\n",
    "\"\"\"\n",
    "import random\n",
    "\"\"\"\n",
    "print(\"111\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7cb06d61",
   "metadata": {},
   "source": [
    "## 2.2 格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0d3a635",
   "metadata": {},
   "source": [
    "## 2.21字符串的拼接实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ced872c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的姓名：Erdaty\n",
      "请输入你的年龄：16\n",
      "请输入你的职业：aaa\n",
      "请输入你的薪水：100000000000000\n"
     ]
    }
   ],
   "source": [
    "#指定格式的简历\n",
    "\n",
    "#用户输入信息\n",
    "name = input(\"请输入你的姓名：\")\n",
    "age = input(\"请输入你的年龄：\")\n",
    "Job = input(\"请输入你的职业：\")\n",
    "salary = input (\"请输入你的薪水：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "20ccf215",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------INFO Erdaty----------\n",
      "姓名：Erdaty\n",
      "年龄：16\n",
      "工作：aaa\n",
      "salary：100000000000000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO =\"\"\"--------------INFO \"\"\"+ name +\"\"\"----------\n",
    "姓名：\"\"\"+ name +\"\"\"\n",
    "年龄：\"\"\"+ age +\"\"\"\n",
    "工作：\"\"\"+ Job +\"\"\"\n",
    "salary：\"\"\"+ salary\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3610b8fa",
   "metadata": {},
   "source": [
    "* 笔记：上述代码使用的方法是\"字符串的拼接\" ，用+实现"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d029ddd",
   "metadata": {},
   "source": [
    "### 2.22占位符实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "960d4078",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------INFO Erdaty----------\n",
      "姓名：Erdaty\n",
      "年龄：16\n",
      "工作：123\n",
      "薪水：10000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO =\"\"\"--------------INFO \"\"\"+ name +\"\"\"----------\n",
    "姓名：\"\"\"+ name +\"\"\"\n",
    "年龄：\"\"\"+ age +\"\"\"\n",
    "工作：\"\"\"+ Job +\"\"\"\n",
    "薪水：\"\"\"+ salary\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "39173c2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------- INFO Erdaty --------\n",
      "姓名：Erdaty \n",
      "年龄：16\n",
      "薪水：10000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO = \"\"\"-------- INFO %s --------\n",
    "姓名：%s \n",
    "年龄：%s\n",
    "薪水：%s\"\"\"%(name,name,age,salary)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8cc94652",
   "metadata": {},
   "source": [
    "* 笔记：占位符比较适用于格式化字段较少的文本处理\n",
    ">1.%s占位符是字符串\n",
    ">2.%d占位符是数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b21b4821",
   "metadata": {},
   "source": [
    "### 2.2.3格式化方法：format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "c41f84ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------INFO %Erdaty --------\n",
      "姓名：Erdaty\n",
      "年龄：16\n",
      "工作：Erdaty\n",
      "薪水：100000000000000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "#N:姓名，A：年龄，J：工作， S：薪水\n",
    "INFO = \"\"\"--------INFO %{N} --------\n",
    "姓名：{N}\n",
    "年龄：{A}\n",
    "工作：{J}\n",
    "薪水：{S}\"\"\".format(N = name,J=name, S=salary, A=age)\n",
    "\n",
    "print(INFO)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59c3418f",
   "metadata": {},
   "source": [
    "* 笔记：fomat方法可以解决占位符的两个痛点\n",
    ">1.不在考量位置顺序\n",
    "\n",
    ">2.解决重复字段出现的问题，只需要赋值一次。如上述：N=name,只需写一次即可。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0efacb7",
   "metadata": {},
   "source": [
    "# 3.课本第一章的三个项目 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cd20f66",
   "metadata": {},
   "source": [
    "## 3.1项目一：判断时钟奇数分钟"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "42a5fa57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "63574698",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "datetime.today().second"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f438d8e",
   "metadata": {},
   "source": [
    "## 3.2项目二： 执行5次，每次等待随机秒钟，输出当前秒钟为奇数、偶数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "79f8a7db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd second.\n",
      "Not an odd second.\n",
      "This second seems a little odd.\n",
      "Not an odd second.\n",
      "Not an odd second.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time) # 时间静止wait_time的时间\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "a674dede",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "c0a3e09c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.6262880289779874\n",
      "0.10655047643295068\n",
      "0.21695170274683373\n",
      "0.5768379953863054\n",
      "0.1151937068195239\n",
      "0.48008562039216274\n",
      "0.011077130220452425\n",
      "0.8333516643626386\n",
      "0.05997094389611812\n",
      "0.11416413170110296\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print(random.random())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "e05e4fb3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "4\n",
      "3\n",
      "4\n",
      "6\n",
      "6\n",
      "6\n",
      "3\n",
      "1\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c39128a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
